package com.stn.zjx.givingtreasure.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.orhanobut.logger.Logger;
import com.stn.zjx.givingtreasure.activity.bi.EthTransferDetailActivity;
import com.vondear.rxtools.RxActivityTool;


import org.json.JSONException;
import org.json.JSONObject;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by 朱俊鑫 on 2018-3
 */

public class PushBroadCastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            Bundle bundle = intent.getExtras();
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);

        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {

        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
                 Bundle bundle = intent.getExtras();
               String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
            try {
                JSONObject data=new JSONObject(extras);
                if(!TextUtils.isEmpty(data.getString("txHash"))){
                    Intent rd_eth_detail = new Intent(context, EthTransferDetailActivity.class);
                    rd_eth_detail.putExtra("txHash",data.getString("txHash"));
                    rd_eth_detail.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(rd_eth_detail);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }



}
